Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Text
Public Class gaValidation
    Dim vAchar As Array
    Dim vAnum As Array
    Dim objdata As New GetData
    Public msg As String
    Public Const cSESSION_ID = 0
    Public Const cCOMPANY_ID = 1
    Public Const cGAPORTAL_ID = 2
    Public Const cUSER_ID = 3
    Public Const cINCIDCONTEXT = 4
    Public Const cINGIDCONTEXT = 5
    Public Const cLOGINDATETIME = 6
    Public Const cLASTACTIVITY = 7
    Public Const cUSERPERMISSIONSSTRING = 8
    'Public Const cTERMINAL_PIN = 9
    Public Const cROLE_ID = 9
    Public Const cMEMBER_TYPE = 10
    'Public Const cTERMINAL_NAME = 10
    Public Const cTERMINAL_NUMBER = 11
    Public Const cTERMINAL_MARKET = 12
    'Public Const cACCESSLEVEL = 9
    Public aUserSession(13) As String
    Public strConn As String
    'Dim objUs As UserManagement.UserSessionManager
    'Const ALPHA_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    'Const NUMERIC_CHARS = "0123456789"
    'Const MISC_CHARS = " .,_-"
    'Const ALPHA_NUMERIC_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
    Public Function GetCompany(ByVal strUID As String, ByVal GID As String) As ArrayList
        Dim sSQL As String = ""
        Dim strDB As String = ""
        Dim sErr As String = ""
        Dim i As Integer
        Dim Ds As New DataSet
        Dim aCompanies As ArrayList = New ArrayList
        Dim objSql As GetData
        Dim dr As DataRow
        objSql = New GetData
        If strUID = "000000" Then
            sSQL = sSQL & "  SELECT DISTINCT  SUBSTR(c.Company_Name,0,24)   "
            sSQL = sSQL & "  ,c.Merchant_ID   FROM  EN_GA_MERCHANTS c"
        End If
        objdata.Dataset(sSQL, "merchants", sErr, Ds)
        If sErr = Nothing Then
            For i = 0 To Ds.Tables(0).Rows.Count - 1
                dr = Ds.Tables(0).Rows(i)
                aCompanies.Add(Trim(dr(1)) & "  " & Trim(dr(0)))
            Next
        End If
        'If Not IsNothing(aCompanies) Then
        '    Return aCompanies
        'End If
        Return aCompanies
    End Function
    Public Sub getURL(ByVal CurrtUrlstring As String, ByRef imgpath As String, ByRef strURL As String)
        'Private Function ReadURLPageName(ByVal strurl As String) As String
        Dim arrTemp As Array
        Dim intPageNamePos As Integer
        'Dim intcurrpagePos As Integer
        Dim strTemp As String
        'Dim arrCurrURL As Array
        'Dim currtURL As String '= Request.Url.ToString

        arrTemp = Split(Currturlstring, "/")
        intPageNamePos = arrTemp.GetUpperBound(0)
        strTemp = arrTemp(intPageNamePos)
        If strTemp = "adm_default.aspx" Then
            strURL = CurrtUrlstring
            imgpath = "Admin/images"
        Else
            strURL = "./" & arrTemp(intPageNamePos - 1) & "/" & strTemp & ""
            imgpath = "../images"
        End If
        'If InStr(strTemp, "?") > 0 Then
        '    arrTemp = Split(strTemp, "?")
        '    ReadURLPageName = LCase(arrTemp(0))
        'Else
        '    ReadURLPageName = strTemp
        'End If
    End Sub

    'Public Function userlogin(ByVal strUserid As String, ByVal Password As String) As String()
    '    Dim strSQL As String = ""
    '    Dim bExist As Boolean = False
    '    Dim UID As String = ""
    '    Dim GID As String = ""
    '    Dim CID As String = ""
    '    'Dim strActive As Integer
    '    Dim RoleID As Integer
    '    Dim SessionID As String = ""
    '    Dim Dr As SqlDataReader
    '    Dim strError As String = ""
    '    Dim intValidEmail As Integer
    '    Dim Membertype As String = ""
    '    'Dim objUs As UserManagement.UserSessionManager
    '    intValidEmail = InStrRev(strUserid, "@")

    '    strSQL = " Select User_id, GAPortal_ID, Company_ID, role_id, Member_Type "
    '    strSQL += " from users where password=' " & Password & "' "
    '    If intValidEmail > 0 Then
    '        strSQL += " and email_address=' " & strUserid & "'"
    '    Else
    '        strSQL += " and user_id=' " & strUserid & "'"
    '    End If


    '    Try
    '        objdata.DBConnection = strConn
    '        Dr = objdata.DataReader(strSQL, strError)
    '        If Len(strError) = 0 Or IsNothing(strError) Then
    '            Do While Dr.Read()
    '                UID = Dr.GetString(0).ToUpper
    '                GID = Dr.GetInt16(1)
    '                CID = Dr.GetInt16(2)
    '                RoleID = Dr.GetInt16(3)
    '                Membertype = Dr.GetString(4).ToUpper
    '            Loop
    '        Else
    '            msg = strError
    '        End If

    '        If Len(UID) > 0 Then
    '            If Len(UID) > 0 Then
    '                objUs = New UserManagement.UserSessionManager
    '                SessionID = objUs.LogInUser(UID, GID, CID, Password)
    '                If Not IsNothing(SessionID) And SessionID <> "1" Then
    '                    aUserSession = objUs.getSessionVar
    '                    aUserSession(cSESSION_ID) = SessionID
    '                    aUserSession(cCOMPANY_ID) = CStr(CID)
    '                    aUserSession(cGAPORTAL_ID) = GID
    '                    aUserSession(cUSER_ID) = UID
    '                    aUserSession(cINCIDCONTEXT) = CStr(CID)
    '                    aUserSession(cINGIDCONTEXT) = GID
    '                    aUserSession(cLOGINDATETIME) = ""
    '                    aUserSession(cLASTACTIVITY) = ""
    '                    aUserSession(cROLE_ID) = CStr(RoleID)
    '                    aUserSession(cMEMBER_TYPE) = Membertype
    '                End If
    '            Else

    '                msg = "If you don't know your Account ID or your Password, feel free to contact us at:404-604-6000"
    '            End If


    '        Else

    '            msg = "If you don't know your Account ID or your Password, feel free to contact us at:404-604-6000"
    '        End If
    '    Catch ex As SqlException
    '        'ErrMessage("InsertUserSQL", ex.Message)
    '        msg = ex.Message
    '    End Try
    '    If Not IsNothing(aUserSession) Then
    '        Return aUserSession
    '    Else
    '        Return Nothing
    '    End If
    '    'If IsArray(aUserSession) Then
    '    '    If aUserSession(cCOMPANY_ID) = "0" Then
    '    '        sHUDMsg = "SU::" & aUserSession(cUSER_ID) & " logged in."
    '    '    ElseIf aUserSession(cVIAKLIX_ID) = "000000" Then
    '    '        sHUDMsg = "SA(" & aUserSession(cCOMPANY_ID) & ")::" & aUserSession(cUSER_ID) & " logged in."
    '    '    Else
    '    '        sHUDMsg = aUserSession(cVIAKLIX_ID) & "::" & aUserSession(cUSER_ID) & " logged in."
    '    '    End If
    '    'Else
    '    '    sHUDMsg = "Welcome to the&nbsp;" & application("AppName") & "&nbsp;Administration Area."
    '    'End If
    'End Function
    'Public Function checklogin(ByVal UID As String, ByVal strpwd As String) As String()
    '    Dim aUserSession(13) As String
    '    Dim strUID, strMID As String
    '    Dim intUID, intMID As Integer
    '    'LogInUser(cid,gid,uid,strpwd)
    '    If UID = "000000" Then
    '        aUserSession(cSESSION_ID) = "DBC123456788909876"
    '        aUserSession(cCOMPANY_ID) = "0"
    '        aUserSession(cVIAKLIX_ID) = "000000"
    '        aUserSession(cUSER_ID) = "000000"
    '        aUserSession(cINCIDCONTEXT) = "0"
    '        aUserSession(cINVIDCONTEXT) = "000000"
    '        aUserSession(cACCESSLEVEL) = "5"
    '    Else
    '        'check_user(UID, strpwd, intUID, intMID)
    '        strUID = intUID
    '        strMID = intMID
    '        aUserSession(cSESSION_ID) = "DBC123456788909876"
    '        aUserSession(cCOMPANY_ID) = "1"
    '        aUserSession(cVIAKLIX_ID) = "100003"  'strMID
    '        aUserSession(cUSER_ID) = "100003"    'strMID
    '        aUserSession(cINCIDCONTEXT) = "1"
    '        aUserSession(cINVIDCONTEXT) = "100003"  'strMID
    '        aUserSession(cACCESSLEVEL) = "5"

    '    End If
    '    Return aUserSession
    'End Function
    'Public Function Get_SessionVar(ByVal UID As String, ByVal MID As String) As String()
    '    Dim aUserSession(13) As String
    '    Dim strUID, strMID As String
    '    Dim intUID, intMID As Integer

    '    If UID = "000000" Then
    '        aUserSession(cSESSION_ID) = "DBC123456788909876"
    '        aUserSession(cCOMPANY_ID) = "0"
    '        aUserSession(cVIAKLIX_ID) = "000000"
    '        aUserSession(cUSER_ID) = "Administrator"
    '        aUserSession(cINCIDCONTEXT) = "0"
    '        aUserSession(cINVIDCONTEXT) = "000000"
    '    Else

    '        aUserSession(cSESSION_ID) = "DBC123456788909876"
    '        aUserSession(cCOMPANY_ID) = "1"
    '        aUserSession(cVIAKLIX_ID) = "100003"  'strMID
    '        aUserSession(cUSER_ID) = "100003"    'strMID
    '        aUserSession(cINCIDCONTEXT) = "1"
    '        aUserSession(cINVIDCONTEXT) = "100003"  'strMID

    '    End If
    '    Return aUserSession
    'End Function
    Public Function checkPwd(ByVal pwd As String) As Boolean
        Dim i, a As Integer
        Dim validpwd1, validpwd2 As Integer
        Dim valid1, valid2 As Boolean
        vAchar = Split("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,!,@,#,$,%,^,&,*,(),_,-,=,+,<,>,?,/,:,;,',[,],{,},|,\,`,~", ",")
        vAnum = Split("1,2,3,4,5,6,7,8,9,0", ",")
        Dim errmsg As String
        '--  Makes certain the NEW password is at least 7 digits long
        For i = 0 To UBound(vAchar)
            validpwd1 = InStr(1, pwd, vAchar(i), vbTextCompare)
            If CLng(validpwd1) > 0 Then
                valid1 = True
                Exit For
            End If
        Next

        If valid1 Then
            For a = 0 To UBound(vAnum)
                validpwd2 = InStr(pwd, vAnum(a))
                If CLng(validpwd2) > 0 Then
                    valid2 = True
                    Exit For
                End If
            Next

            If Not valid2 Then
                errmsg = "Your password must contain at least one number."

            End If
        Else
            If Not valid1 Then
                errmsg = "Your password must contain at least one letter."

            End If
        End If
        If valid1 = True And valid2 = True Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Function Isemail(ByVal strEmail As String) As Boolean

        Dim intValidEmail As Integer
        intValidEmail = InStrRev(strEmail, "@")
        If intValidEmail > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
    
    Public Function GetError() As String
        GetError = msg
        Exit Function
    End Function
End Class
